package fr.afcepf.atod19.groupeJV.data.implementations;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.atod19.groupeJV.data.interfaces.IDataSupport;
import fr.afcepf.atod19.groupeJV.entity.Support;

@Stateless
public class DataSupportImpl implements IDataSupport {
	
	//ATTRIBUTS
	
	@PersistenceContext(unitName="ProjetAtod")
	EntityManager em;
	
	public List<Support> getAllSupport() {
		
		return null;
	}
	
	@Override
	public int getIDSupportRechercheByNom(String nomSupport) {
		
		Query query = em.createQuery("FROM Support s "
									+ "WHERE s.libelleSupport = :pNomSupport");
		query.setParameter("pNomSupport", nomSupport);
		
		//******     P'tite roustine faite maison :D     ******
		Support retour;
		try {
			retour = (Support) query.getSingleResult();
		} catch (Exception e) {
			retour = new Support();
			retour.setIdSupport(-1);
		}
		//*****************************************************
		
		return retour.getIdSupport();
	}
}
